<template>
  <div>
    <FormPanel
      ref="formPanel"
      :cols="4"
      :list="formList"
      formType="add"
      labelWidth="100"
      :isSubmitBtn="false"
    />

    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :datakey="'records'"
      :height="'auto'"
      :isSelectColumn="false"
      :isToperInfo="false"
      columnsRef="ysj2019092401CareObjDetail"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>

    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">取 消</el-button>
    </div>
  </div>
</template>
<script>
import {
  getCareTaskListById
} from '@/api/customerCare/saleVisit/careTaskSearch';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'CareObjDetail',
  mixins: [dictionary],
  props: {
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  data(){
    return {
      formList: this.createFormList(),
      fetchapi: getCareTaskListById,
      columns: this.createTableColumns(),
      fetchParams: {careTaskId:this.rowData.careTaskId}
    }
  },
  created() {
    this.init();
  },
  methods: {
    init(){
      this.formList.forEach(x => {
        x.initialValue = isNaN(this.rowData[x.fieldName])?this.rowData[x.fieldName]:parseInt(this.rowData[x.fieldName]);
      });
    },
    createTableColumns(){
      let data = [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '客户编号',
          dataIndex: 'customerNo',
          sorter: true,
          filter: true,
          width: 125,
          filterType: 'input'
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '性别',
          dataIndex: 'gender',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <div>{this.createDictText(props.row.gender, '1002')}</div>;
          }
        },
        {
          title: '手机号',
          dataIndex: 'mobile',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '出生日期',
          dataIndex: 'birthday',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
      if(this.rowData["careTypeCode"]=="15721006"){
        data.push({
          title: '客户意向',
          dataIndex: 'khyx',
          sorter: true,
          filter: true,
          filterType: 'input'
        });
      }
      if(this.rowData["careTypeCode"]=="15721005"){
        data.push({
          title: '假日日期',
          dataIndex: 'specialHoliday',
          sorter: true,
          filter: true,
          filterType: 'input'
        });
      }
      if(this.rowData["careTypeCode"]=="15721002"){
        data.push({
          title: '出库日期',
          dataIndex: 'stockInOutStockDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },{
           title: 'VIN',
           dataIndex: 'vin',
           sorter: true,
           filter: true,
           filterType: 'input',
           width: 150
         });
      };
      if(this.rowData["careTypeCode"]=="15721003"){
        data.push({
          title: '意向级别',
          dataIndex: 'intentLevel',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <div>{this.createDictText(props.row.intentLevel, '1519')}</div>;
          }
        })
      };
      data.push({
          title: '客户类型',
          dataIndex: 'customerType',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <div>{this.createDictText(props.row.customerType, '1523')}</div>;
          }
        },
        {
          title: '客户来源',
          dataIndex: 'customerFrom',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '关爱状态',
          dataIndex: 'careStatus',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <div>{this.createDictText(props.row.careStatus, '1592')}</div>;
          }
        },
        {
          title: '关爱结果',
          dataIndex: 'careResult',
          sorter: true,
          filter: true,
          filterType: 'input'
        },{
           title: '要求完成日期',
           dataIndex: 'requiredDate',
           sorter: true,
           filter: true,
           filterType: 'input'
         });
      return data;
    },
    createFormList(){
      return [
        {
          type: 'INPUT',
          label: '任务编号',
          fieldName: 'taskNo',
          disabled: true,
          placeholder: '请输入任务编号'
        },
        {
          type: 'SELECT',
          label: '关爱类型',
          fieldName: 'careTypeCode',
          disabled: true,
          placeholder: '请选择',
          itemList: this.createDictList('1572')
        },
        {
          type: 'INPUT',
          label: '关爱名称',
          fieldName: 'careName',
          disabled: true,
          placeholder: '请输入任务编号'
        },
        {
          type: 'INPUT',
          label: '关爱人员',
          fieldName: 'employeeName',
          disabled: true,
          placeholder: '请选择关爱人员'
        }
      ]
    },
    closeDialog(type) {
      this.$emit('close', false, type);
    }
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  }
}
</script>
